package com.lagou.cl.service.impl;

import com.lagou.cl.annotation.MyAutowired;
import com.lagou.cl.annotation.MyQuerlifer;
import com.lagou.cl.annotation.MyService;
import com.lagou.cl.annotation.MyTransactions;
import com.lagou.cl.dao.AccountDao;
import com.lagou.cl.pojo.Account;
import com.lagou.cl.service.TransferService;

/**
 * @author 程  林
 * @date 2020-04-01 10:33
 * @description //
 * @since V1.0.0
 */
@MyService("transferServiceImpl")
public class TransferServiceImpl implements TransferService {


	@MyAutowired
	@MyQuerlifer("jdbcAccountDaoImpl")
	private AccountDao accountDao;


	@Override
	@MyTransactions
	public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {

		Account from = accountDao.queryAccountByCardNo(fromCardNo);
		Account to = accountDao.queryAccountByCardNo(toCardNo);

		from.setMoney(from.getMoney() - money);
		to.setMoney(to.getMoney() + money);


		accountDao.updateAccountByCardNo(to);

		int c = 1 / 0;


		accountDao.updateAccountByCardNo(from);
	}
}
